package com.xyzwps.lib.ap;

import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.TypeElement;
import java.util.ArrayList;
import java.util.Set;

public final class ApUtils {
    public static ArrayList<TypeElement> getTypes(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        var types = new ArrayList<TypeElement>();
        for (TypeElement annotation : annotations) {
            for (var element : roundEnv.getElementsAnnotatedWith(annotation)) {
                if (element instanceof TypeElement typeElement) {
                    types.add(typeElement);
                }
            }
        }
        return types;
    }

    public static String packageName(String canonicalName) {
        var index = canonicalName.lastIndexOf('.');
        return index == -1 ? "" : canonicalName.substring(0, index);
    }

    private ApUtils() throws IllegalAccessException {
        throw new IllegalAccessException("???");
    }
}
